<?php

namespace addons\kzvote\controller;

use addons\kzvote\model\MusicModel;
use app\common\model\kzvote\music\Cate as CateModel;

/**
 * 背景音乐
 */
class Music extends Base
{
    /**
     * 分类
     */
    public function cate()
    {
        $MusicCate = new CateModel;
        $list      = $MusicCate->where('status', '10')->order('weigh', 'desc')->field('id,name')->select();
        $this->success('',$list);
    }

    public function index()
    {
        $cate_id    = $this->request->param('cate_id', 0);
        $keyword    = $this->request->param('keyword', '');
        $MusicModel = new MusicModel();
        if ($cate_id > 0) {
            $MusicModel->where('cate_id', $cate_id);
        }
        if ($keyword) {
            $MusicModel->where('name', 'like', "%{$keyword}%");
        }
        $list = $MusicModel->where('status', '10')
            ->order('weigh', 'desc')
            ->field('id,cate_id,name,author,url,type')
            ->paginate(20, true);
        $this->success('',$list);
    }



}
